# -*- coding: utf-8 -*-
"""
# --------------------------------------------------------
# @Author : Pan
# @E-mail : 
# @Date   : 2025-11-19 15:56:37
# @Brief  : 接口文档：https://github.com/ggml-org/llama.cpp/tree/master/tools/server
            TODO 启动服务
            model=data/models/Qwen/Qwen3-VL-2B-Instruct-GGUF/Qwen3VL-2B-Instruct-Q8_0.gguf
            mmproj=data/models/Qwen/Qwen3-VL-2B-Instruct-GGUF/mmproj-Qwen3VL-2B-Instruct-F16.gguf
            llama-server -m $model --mmproj $mmproj
# --------------------------------------------------------
"""
import requests
import base64
from pybaseutils import http_utils, json_utils, image_utils, base64_utils

url = "http://localhost:8080/v1/chat/completions"
image_file = "../../data/image1.jpg"


def encode_image(image_path):
    with open(image_path, "rb") as f:
        return base64.b64encode(f.read()).decode("utf-8")


image_b64 = encode_image(image_file)

payload = {
    "model": "qwen3-vl-2b-instruct",
    "messages": [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "请描述这张图片"},
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}
                }
            ]
        }
    ],
    "temperature": 0.7,
    "max_tokens": 256
}

payload = {
    "model": "qwen3-vl-2b-instruct",
    "messages": [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "请分析这个视频"},
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}
                },
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}
                },
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}
                }
            ]
        }
    ],
    "temperature": 0.7,
    "max_tokens": 256
}

# response = requests.post(url, json=payload)
# print(response.json()["choices"][0]["message"]["content"])
response = http_utils.post(url, params=payload)
print(json_utils.formatting(response))
